<?php
//       PHPcongrats - Holiday and Birthday Mailer
//     
//    Copyright (C) 2011  Matthias Nass
//
//    This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.
session_start();

if ($_SESSION['loggedin'] == true){
     $id = (int) $_GET['id'];
     include 'DBconnect.php';
     $query = "SELECT * FROM persons WHERE id=$id;";
     $result = mysql_db_query($database, $query, $link);
     $row = mysql_fetch_row($result);
     $firstname = $row['1'];
     $lastname = $row['2'];
     $title = $row['3'];
     $hometown = $row['4'];
     $gender = $row['5'];
     if($gender == 'w') $mw ='Frau';
     if($gender == 'm') $mw ='Herr';
     $email  = $row['6'];
     $birthdate  = $row['7'];
     $birtgrats  = $row['8'];
     $lang  = $row['9'];
?>
<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Festage</title>
<link rel="stylesheet" type="text/css" href="./styles.css">
<script type="text/javascript" src="./scripts.js"></script>
</head>
<body>
<h2>PHPcongrats <img src='./icons/rosette.png' alt='Rosette'/></h2>
<h1>Festage zu einer Person <img src='./icons/rosette.png' alt='holidays'/></h1>
	<p class="message">
	    <?php if($_SESSION['message'] == ''){}else{?>
		<img src='./icons/error.png' alt='attention'/> <?php echo $_SESSION['message']; }?>
	</p>
	
	<p class="data">
	    <?php echo $mw." ".$title." ".$firstname." ".$lastname. "  | Sprache:".$lang ;?>
	</p>
	<p>
	Feiertage f&uuml;r Person ausw&auml;hlen:
	</p>
	<div>
		<div style="float: left;">
	<?php 
                  $query="SELECT id,name,region FROM holidays WHERE id>1;";
                  $result = mysql_db_query($database, $query, $link);
                  echo "<form name='holidays' action='actionaddholiday2person.php' method='POST'>";
                  echo "<input type='hidden' name='id' value='".$id."' />";
                  echo "<select class='multiple' name='holi_id[]' multiple>";
                  while ($row=mysql_fetch_row($result)){
                       echo "<option value='".$row[0]."'>".$row[0]." | ".$row['1']." | ".$row['2']." | ".$row['3']."</option>";
                  }
                  echo "</select>  <input class='graf' type='image' src='./icons/add.png' />";  
		?>
			<br><a href="./persons.php"><img src='./icons/cross.png' alt='Cancel'/> Abbrechen</a>
		
		</div>
		
		<div>
		<table>
		
		<?php 
		      require_once 'datefunction.php';
		      $query = "SELECT * FROM congrats as c LEFT JOIN holidays on (holidays_id=id)  where c.persons_id=$id;";
		      $result2 = mysql_db_query($database, $query, $link);
              while ($row = mysql_fetch_array($result2, MYSQL_NUM)) {
              if ($row[6] == 1) {$revise="Ja";} else { $revise="Nein";};
              echo "<tr><td>";
              printf ("Datum: %s  Name: %s Wiederholend: %s", date_mysql2german($row[5]), $row[4], $revise);
              echo "</td><td><a href='./personholidays.php?id=".$id."' onclick='rMConfirm(\"./actionremcongrat.php?a=".$row[0]."b=".$row[1]."\");'><img src='./icons/cross.png' alt='delete user'/></a></td></tr>";                
          }
          mysql_close($link);?>
		</table>
		</div>
	</div>
	<br>
</body>
</html>
<?php
		$_SESSION['message'] = "";
} else{
    $_SESSION['last_location'] = "./personholidays.php";
	header( 'Location: http:./login.php' );
}
?>
